#include "boolfield.h"
#include <QCheckBox>
#include <qplugin.h>
#include <QDebug>

BoolField::BoolField()
{
}

QWidget *BoolField::createDelegate(const QVariantMap &properties)
{
    QCheckBox *check = new QCheckBox;

    if (properties.contains("text"))
        check->setText(properties["text"].toString());

    return check;
}

void BoolField::setEditable(QWidget *delegate, bool editable)
{
    QCheckBox *edit = (QCheckBox *)delegate;
    edit->setCheckable(editable);
}

QVariant BoolField::data(QWidget *delegate) const
{
    QCheckBox *edit = (QCheckBox *)delegate;
    int checked = edit->isChecked();
    return checked;
}

void BoolField::setData(QWidget *delegate, const QVariant &data)
{
    QCheckBox *edit = (QCheckBox *)delegate;
    edit->setChecked(data.toBool());
}

void BoolField::connectToDataChange(QWidget *delegate, QObject *reciever, const char *slot)
{
    QCheckBox *edit = (QCheckBox *)delegate;
    connect(edit, SIGNAL(toggled(bool)), reciever, slot);
    edit->setChecked(true);
    edit->setChecked(false);
}

void BoolField::clear(QWidget *delegate)
{
    QCheckBox *edit = (QCheckBox *)delegate;
    edit->setChecked(false);
}

Q_EXPORT_PLUGIN2(bool-field, BoolField)
